/*
Problem Id:1048  User Id:tq 
Memory:300K  Time:46MS
Language:C++  Result:Accepted

	author: TangQiao , Wind @ Beijing Normal University

	problem name: Quadtree II or: Florida Jones strikes back


	source :  BNU Online Judge
	
	problem type:	递归题
	
	problem description: 
	
	problem solution: 递归
	
	
	faults:1.读数据时S1数据开小了,造成读入在N=256时就读入失败了.
			 以后开数组时还是应该事先估计一下数据可能的最大值.
	
	date : 2005. 北师大校队个人练习赛
	
*/

#include <stdio.h>
#include <string.h>

int n;
char map[550][550];


int change(char a, char b)
{
	int t1, t2, tot;
	if (a>='0' && a<='9') t1=a-'0';
	else t1=a-'a'+10;
	if (b>='0' && b<='9') t2=b-'0';
	else t2=b-'a'+10;
	tot=t1*16+t2;
	return tot;
}


void input()
{
	int i,j,k,tot,l;
	char s1[1000],s2[1000]; // length: 512/8*5
	scanf("%s%s", s1, s2);
	scanf("%d", &n);
	scanf("%s%s", s1, s2);
	scanf("%d", &n);
	scanf("%s%s%s%s%s", s1, s1, s1, s1, s1);
	for (i=1;i<=n;i++)
	{
		scanf("%s", s1);
		int start=2;
		for (k=1;k<=n;k+=8)
		{
			tot=change(s1[start],s1[start+1]);
			start+=5;
			for (l=0;l<8;l++)
			{
				map[i][k+l]=tot%2;
				tot/=2;
			}
		}		
	}
	scanf("%s", s1);
//check]
/*
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=n;j++)
			if (map[i][j]==1)
				printf("B");
			else 
				printf("W");
		printf("\n");
	}
	printf("\n");
*/
}

int checkarea(int x, int y,int len)
{
	int i,j,tox,toy,a;
	tox=x+len;
	toy=y+len;
	a=map[x][y];
	for (i=x;i<tox;i++)
		for (j=y;j<toy;j++)
			if (map[i][j]!=a)
				return 0;
	return 1;			
}

void di(int x, int y, int len)
{
	int to;
	if (checkarea(x,y,len))
	{
		if (map[x][y]==1) printf("B");
		else printf("W");
	}
	else
	{
		to=len/2;
		printf("Q");
		di(x,y,to);
		di(x,y+to,to);
		di(x+to,y,to);
		di(x+to,y+to,to);
	}
}

main()
{
//	freopen("out.txt", "r", stdin);
//	freopen("out2.txt", "w", stdout);
	input();
	printf("%d\n",n);
	di(1,1,n);	
	printf("\n");

	return 0;
}







